package br.edu.ufcg.lsd.wbis.ui.client.ui.management;

import br.edu.ufcg.lsd.wbis.ui.client.beans.UserInfo;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.widgets.MessageBox;

/**
 * @author Renato Miceli
 */
public class UserInfoUpdaterCallback implements AsyncCallback<UserInfo> {

	private final InfoManager<UserInfo> infoManager;

	public UserInfoUpdaterCallback(InfoManager<UserInfo> infoManager) {
		this.infoManager = infoManager;
	}

	/**
	 * {@inheritDoc}
	 */
	public void onFailure(Throwable caught) {
		System.out.println("FAILURE: " + caught.getCause());
		MessageBox.alert("Error", "Could not update user information.");
	}

	/**
	 * {@inheritDoc}
	 */
	public void onSuccess(UserInfo result) {
		if (result == null) {
			return;
		}
		result.setPassword(this.infoManager.getInfo().getPassword());
		this.infoManager.setInfo(result);
	}

}